<?php

//<editor-fold defaultstate="collapsed" desc="License & Copyright">
/*
 * @license
 */

/**
 *
 * @author Jevgeni Geimanen (jevgeni.geimanen@gmail.com)
 */
//</editor-fold>
class SCCollection implements Iterator, Countable {
    protected $_UIDs = array();
    protected $_Collection = array();
    /**
     *
     * @param SCStruct $element
     * @return Collection
     * @throws Exception 
     */
    public function Add($element) {
        //if (isset($this->_UIDs[$uid = $element->getUID()])) throw new Exception("Element `{$uid}` already exists in Collection");
        //$this->_UIDs[$uid] = $element;
        $this->_Collection[] = $element;
        return $element;
    }
    //<editor-fold defaultstate="collapsed" desc="Interface::Countable">
    public function count() {
        return count($this->_Collection);
    }

    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Interface::Iterator">
    private $index = 0;
    /**
     *
     * @var Component
     */
    private $current = null;
    public function current() {
        return $this->current = $this->_Collection[$this->index];
    }

    public function key() {
        return $this->current->getUID();
    }

    public function next() {
        ++$this->index;
    }

    public function rewind() {
        $this->index = 0;
    }

    public function valid() {
        return $this->index < count($this->_Collection);
    }

    //</editor-fold>
}

?>
